package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.TrainOrderBean;
import com.example.administrator.yuejian2.service.MyTrainOrderDetailService;
import com.example.administrator.yuejian2.service.MyTrainOrderService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;

public class TrainOrderDetailModel {
    private Retrofit retrofit;
    private MyTrainOrderDetailService myTrainOrderDetailService;


    public TrainOrderDetailModel ()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL1)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        myTrainOrderDetailService=retrofit.create(MyTrainOrderDetailService.class);
    }


    public void getTrainOrderDetail(String trainorder_id, final RetrofitListener listener)
    {
            Call<List<TrainOrderBean>> call=myTrainOrderDetailService.getTrainOrder(trainorder_id);
                    call.enqueue(new Callback<List<TrainOrderBean>>() {
                        @Override
                        public void onResponse(Call<List<TrainOrderBean>> call, Response<List<TrainOrderBean>> response) {
                            listener.onSuccess(response.body(),1);
                        }

                        @Override
                        public void onFailure(Call<List<TrainOrderBean>> call, Throwable t) {
                                listener.onFail();
                        }
                    });
    }


    public void getTrainOrder(String train_id, final RetrofitListener listener)
    {
        Call<List<TrainOrderBean>> call=myTrainOrderDetailService.getTrainOrderById(train_id);
        call.enqueue(new Callback<List<TrainOrderBean>>() {
            @Override
            public void onResponse(Call<List<TrainOrderBean>> call, Response<List<TrainOrderBean>> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<List<TrainOrderBean>> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
